﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using MySql.Data.MySqlClient;
using DAL;

namespace BLL
{
    public class CarService
    {
        public static bool AddCar(Model.Car c)
        {
            string sql = @"insert into carbill(CarNumber,StartTime)values(@CarNumber,@StartTime)";
            MySqlParameter[] parameters = new MySqlParameter[2] { new MySqlParameter("CarNumber", c.CarNumber), new MySqlParameter("StartTime", c.StartTime) };
            if (sqlHelper.ExcuteNonquery(sql, parameters) > 0)
                return true;
            else
                return false;
        }

        public static DateTime OutCar(Car c)
        {
            string sql = @"select StartTime from carbill where CarNumber=@CarNumber";
            MySqlParameter[] parameters = new MySqlParameter[1] { new MySqlParameter("CarNumber", c.CarNumber) };
            return Convert.ToDateTime(sqlHelper.OutCar(sql,parameters));
        }

        public static void OUTParking(Car c)
        {
            string sql = @"delete from carbill where CarNumber=@CarNumber";
            MySqlParameter[] parameters = new MySqlParameter[1] { new MySqlParameter("CarNumber", c.CarNumber) };
            sqlHelper.ExcuteNonquery(sql, parameters);
        }
    }
}
